import { getHomeInitData } from "../../api"

const state = {
  initList: [],
}
const getters = {
  levelList(state) {
    return state.initList.slice(1, 11)
  },
  levelThreeList(state) {
    // 只截取手机数组
    const levelList = state.initList.slice(1, 2)
    // 获取一级分类数组
    const categoryChild = levelList[0].categoryChild
    const levelThreeList = []
    // 跳过二级分类，循环遍历取值三级对象
    categoryChild.forEach((level) => {
      level.categoryChild.forEach((obj) => {
        levelThreeList.push(obj)
      })
    })
    return levelThreeList.slice(0, 23)
  },
}
const actions = {
  async getHomeInitData({ commit }) {
    const result = await getHomeInitData()
    commit("SET_HOME_INIT_DATA", result.data)
  },
}
const mutations = {
  SET_HOME_INIT_DATA(state, data) {
    state.initList = data
  },
}
export default {
  state,
  getters,
  actions,
  mutations,
  namespaced: true,
}
